package the.broccoli.weixin.service.dto;

import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class WeiXinUnifiedOrderResultDTO implements Serializable {
    private static final long serialVersionUID = 5858268316983103582L;
    private String appid;
    private String timeStamp;
    /**
     * 随机字符串.
     */
    private String nonceStr;

    /**
     * 微信生成的预支付回话标识，用于后续接口调用中使用，该值有效期为2小时
     */
    private String prepayId;

    private String paySign;

    private String signType = "MD5";

    public void setPrepayId(String prepayId) {
        if (StringUtils.hasText(prepayId)) {
            this.prepayId = "prepay_id=" + prepayId;
        }
    }

    public Map<String, String> getSignParams() {
        Map<String, String> map = new HashMap<>(5);
        map.put("appId", appid);
        map.put("timeStamp", timeStamp);
        map.put("nonceStr", nonceStr);
        map.put("package", prepayId);
        map.put("signType", signType);
        return map;
    }
}
